home *** CD-ROM | disk | FTP | other *** search
/ CGI How-To / CGI HOW-TO.iso / chap4 / 4_4 / comp_c / complete.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-15  |  1019 b   |  60 lines

  1.  
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include "dict.h"
  6. #include "cgilib.h"
  7.  
  8. void main(int argc, char *argv[])
  9. {
  10.     /* Variables for the data. */
  11.     
  12.     char *data = (char *) 0;
  13.     Dictionary dataDict;
  14.     const char *choice , *theUrl;
  15.     
  16.     /*
  17.     * Create a dictionary to hold the data.
  18.     */
  19.     
  20.     dataDict = dict_alloc();
  21.     
  22.     /*
  23.      * Read the data, passing the string data by reference.
  24.      * readData() will alloc space for it. readData() will also determine
  25.      * the request type.
  26.      */
  27.     
  28.     readData(&data);
  29.         
  30.     /*
  31.      * Call parseData() to break the data into key-value pairs.
  32.      * This function will print the pairs.
  33.      */
  34.     if(data) parseData(data,dataDict);
  35.  
  36.     choice = (const char *)dict_valueForKey(dataDict,"choice");
  37.     
  38.     if(choice && !strcmp(choice,"Yahoo"))
  39.       {
  40.         theUrl = "http://www.yahoo.com";
  41.       }
  42.     else
  43.       {
  44.         theUrl = "http://www.webcrawler.com";
  45.       }
  46.  
  47.     /*Output a complete url*/
  48.     
  49.     printf("Location: %s\n\n",theUrl);
  50.  
  51.     
  52.     if(data) free(data);
  53.     
  54.     dict_free(dataDict);
  55.     
  56.     /* End the program */
  57.     exit(0);
  58. }
  59.  
  60.